package modelLayer;

import java.util.List;

/**
 * This class is a modelLayer class of the MSAS system. It holds
 * information on a single schedule. True to our domain model, the schedule
 * class has field visibility to Class and Block.
 * 
 * @author Danny M�lgaard, Anna Kelemen, Jakob Korsgaard
 * 		   
 * @version 1.3.1
 * 					1.3.1: 		Added more extensive documentation. Verified that
 * 								information contained in the Design Class Diagram,
 * 								is in accordance with the information contained in this
 * 								class.
 * 					1.3.2: 		toString() adjusted
 */
public class Schedule {
	
	private int id;
	private int	numberOfBlocks;
	private Class cl;
	private List<Block> blocks;

	
	/**
	 * Instantiating a Schedule object, taking no parameters:
	 */
	public Schedule() {	
	}
	
	/**
	 * Instantiating a Schedule object, taking the following parameters:
	 * 
	 * @param	id		int			id of the classroom, as allocated in the database.
	 */
	public Schedule(int id) {
		
		this.setId(id);
		
	}
	
	/**
	 * Assigns a reference to the cl field, defining the class associated with the schedule.
	 * 
	 * @param 	cl			Class	the class associated with the schedule.					
	 */
	public void setCl(Class cl) {

		this.cl = cl;

	}
	
	/**
	 * Assigns a reference to the blocks field, defining a collection of blocks associated with the schedule.
	 * 
	 * @param 	blocks		List<Block>		the blocks associated with the schedule.					
	 */
	public void setBlocks(List<Block> blocks) {

		this.blocks = blocks;

	}
	
	/**
	 * Assigns a parameter to the numberOfBlocks field, defining the number of blocks to be contained
	 * within the schedule.
	 * 
	 * @param 	numberOfBlocks	int		the number of blocks contained in the schedule.					
	 */
	public void setNumberOfBlocks(int number) {

		this.numberOfBlocks = number;

	}
	
	/**
	 * Assigns a parameter to the id field, defining the uniquely allocated id field in the database.
	 * 
	 * @param 	id		int		the schedules id attribute in the database.					
	 */
	public void setId(int id) {
		
		this.id = id;
		
	}

	/**
	 * Returns the Class object associated with the Schedule object.
	 * 
	 * @return 	cl			Class		the Class object referenced by the Schedule object
	 */
	public Class getCl() {

		return this.cl;

	}

	/**
	 * Returns the collection of Block objects associated with the Schedule object.
	 * 
	 * @return 	blocks		List<Block>		the list of Block objects referenced by the Schedule object
	 */
	public List<Block> getBlocks() {

		return this.blocks;

	}

	/**
	 * Returns the number of blocks in the schedule to the caller.
	 * 
	 * @return 	numberOfBlocks		int		the number of blocks in the schedule.
	 */
	public int getNumberOfBlocks() {
		
		return this.numberOfBlocks;
	
	}

	/**
	 * Returns the schedule's id, as allocated in the database.
	 * 
	 * @return 	id			int		the schedule's id as allocated in the database.
	 */
	public int getId() {
		
		return this.id;
		
	}

	/**
	 * Overrides the object's default toString() method. Returns the object as a String
	 * literal to the caller.
	 * 
	 * return				String	the Schedule object represented as a String object.
	 */
	@Override
	public String toString() {

		return "Skema for: " + cl.getClassName();

	}

	/**
	 * Implements a check, to verify if an object is the same
	 * as this object. Uses class identification number to
	 * verify.
	 * 
	 * @param	o		Object	any object type.
	 * @return	true			if: 
	 * 							object is not null, and
	 * 							object is of type Schedule, and
	 * 							object id field matches this objects id field.
	 * @return	false			if:
	 * 							object is null, or
	 * 							object is not an instance of Schedule, or
	 * 							object id field doesn't match this objects id field.
	 */
	@Override
	public boolean equals(Object o) {
		
		if (o != null && (o instanceof Schedule)){
			Schedule sch = (Schedule) o;
			if (this.getCl().getClassName() != null && this.getCl().getClassName().equals(sch.getCl().getClassName())) {
				return true;
			}
		}
			
		return false;

	}

}
